package com.itheima.HomeWork_day06;

import java.util.Objects;

public class Phone {
    private String brand;
    private String color;

    public Phone() {
    }

    public Phone(String brand, String color) {
        this.brand = brand;
        this.color = color;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;

    }

    //进行toString方法的重写
    @Override
    public String toString() {
        return "Phone{" +
                "brand='" + brand + '\'' +
                ", color='" + color + '\'' +
                '}';
    }

    //对equals方法进行重写,(自动生成)
    // @Override
//    public boolean equals(Object o) {
//        if (this == o) return true;
//        if (o == null || getClass() != o.getClass()) return false;
//        Phone phone = (Phone) o;
//        return Objects.equals(brand, phone.brand) &&
//                Objects.equals(color, phone.color);
//    }
//
    //自己重写
    public boolean equals(Object o) {

        //判断是否为null
        if (o == null) {
            return false;
        }
        //判断两个对象是否相同
        if (this == o) {
            return true;
        }

        //向下转型的判断
        if (o instanceof Phone) {
            //进行向下转型
            Phone po = (Phone) o;

            return this.brand.equals(po.brand) &&
                    this.color.equals(po.color);
        }
        return false;
    }

}
